package com.safety.web.controller;

import com.safety.core.util.Data;
import net.sf.json.JSONObject;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.multipart.MultipartFile;

import java.io.File;
import java.util.*;



/**
 * Created by pinky on 2016/12/14.
 */
@Controller
public class PublicController {
    private Map<String, Object> result = new LinkedHashMap<>();

    /**
     * 400页
     */
    @RequestMapping("/400")
    @ResponseBody
    public Map<String, Object> error400() {
        result.put("code", 400);
        return result;
    }

    /**
     * 404页
     */
    @RequestMapping("/404")
    @ResponseBody
    public Map<String, Object> error404() {
        result.put("code", 404);
        return result;
    }


    /**
     * 500页
     */
    @RequestMapping("/500")
    @ResponseBody
    public Map<String, Object> error500() {
        result.put("code", 500);
        return result;
    }

    // 上传图片
    @RequestMapping(value = "/uploadPic")
    @ResponseBody
    public Object updatePic(MultipartFile file) throws Exception {
        JSONObject json = new JSONObject();
        // 原始名称
        String originalFilename = file.getOriginalFilename();
        // 上传图片
        if (file != null && originalFilename != null
                && originalFilename.length() > 0) {

            // 存储图片的物理路径
            String base = this.getClass().getResource("/").getPath()
                    + "../../upload/cache/";
            // 新的图片名称
            String newFileName = UUID.randomUUID().toString()
                    .replaceAll("-", "").substring(14)
                    + originalFilename.substring(originalFilename
                    .lastIndexOf("."));
            // 新图片
            File newFile = new File(base + newFileName);
            // ThumbPic.createThumbPic(newFile, base);
            // BufferedImage buffer = ImageIO.read(newFile); // 读取图片 报错

            // 将内存中的数据写入磁盘
            file.transferTo(newFile);// newfile 是本地路径
            json.put("message", newFileName);

            return json;

        } else {
            json.put("message", "图片上传出现问题");
            return json;
        }
    }

    @RequestMapping("/interface")
    public String allInterface(Model model) {
        List<Map<String, String>> list = new ArrayList<>();
        Map<String, String> map;
        Map<String, String> map1 = new LinkedHashMap<>();
        map1.put("name", "分割线"); 
        map1.put("url", "=================================================================================");

        list.add(map1);

        map = new LinkedHashMap<>();
        map.put("name", "首页列表");
        map.put("url", Data.URL.base + "home/homePicList");
        System.out.println("sdfsdfsdfsd");
        list.add(map);

        map = new LinkedHashMap<>();
        map.put("name", "首页列表(userId)");
        map.put("url", Data.URL.base + "home/homePicListWithId?userId=");
        list.add(map);

        list.add(map1);

        map = new LinkedHashMap<>();
        map.put("name", "用户-存在?登录:注册");
        map.put("url", Data.URL.base + "user/registerOrLogin?phoneNum=");
        list.add(map);

        map = new LinkedHashMap<>();
        map.put("name", "用户-发送验证码");
        map.put("url", Data.URL.base + "user/sendVerify?phoneNum=");
        list.add(map);

        map = new LinkedHashMap<>();
        map.put("name", "用户-注册填写的昵称和性别");
        map.put("url", Data.URL.base + "user/register?phoneNum=&userName=&sex=");
        list.add(map);

        list.add(map1);

        map = new LinkedHashMap<>();
        map.put("name", "问诊页面-所有医生类别");
        map.put("url", Data.URL.base + "askDoctor/allDoctorClass");
        list.add(map);

        map = new LinkedHashMap<>();
        map.put("name", "问诊页面-按类别搜索医生");
        map.put("url", Data.URL.base + "askDoctor/classForDoctor?classId=");
        list.add(map);

        map = new LinkedHashMap<>();
        map.put("name", "问诊页面-图片");
        map.put("url", Data.URL.base + "askDoctor/pic");
        list.add(map);

        map = new LinkedHashMap<>();
        map.put("name", "问诊页面-图片");
        map.put("url", Data.URL.base + "askDoctor/showDoctor");
        list.add(map);


        list.add(map1);

        
        map = new LinkedHashMap<>();
        map.put("name", "健康商城-所有商品类别");
        map.put("url", Data.URL.base + "healthmall/selectHealthmall");
        list.add(map);

        map = new LinkedHashMap<>();
        map.put("name", "健康商城-类别产品图片");
        map.put("url", Data.URL.base + "healthmall/selecthealthcategories");
        list.add(map);

        map = new LinkedHashMap<>();
        map.put("name", "健康商城-轮播图");
        map.put("url", Data.URL.base + "healthmall/carouselfigure");
        list.add(map);
        list.add(map1);
        
        
        
        
        map = new LinkedHashMap<>();
        map.put("name", "健康圈---标题");
        map.put("url", Data.URL.base + "healthheadlines/selectHealthheadlinestitle");
        list.add(map);
      
        map = new LinkedHashMap<>();
        map.put("name", "健康圈---列表");
        map.put("url", Data.URL.base + "healthheadlines/selectconditionHealthheadlines?id=");
        list.add(map);
        list.add(map1);



        map = new LinkedHashMap<>();
        map.put("name", "快速买药---标题");
        map.put("url", Data.URL.base + "quickmedicine/quickmedicineselect");
        list.add(map);

        map = new LinkedHashMap<>();
        map.put("name", "快速买药---轮播图");
        map.put("url", Data.URL.base + "quickmedicine/carouselfigure");
        list.add(map);


        map = new LinkedHashMap<>();
        map.put("name", "快速买药---分类");
        map.put("url", Data.URL.base + "quickmedicine/carouselfigurefour");
        list.add(map);
        list.add(map1);

        map = new LinkedHashMap<>();
        map.put("name", "健康头条---全部");
        map.put("url", Data.URL.base + "ghostlamp/ghoslaselect");
        list.add(map);








        list.add(map1);
        model.addAttribute("list", list);
        return "/interface";

    }
}
